<script setup lang="ts">
import {markRaw, onMounted, ref} from "vue";
import type {EChartsOption, EChartsType} from "echarts";
import * as echarts from "echarts";
import {useGetHeatmapDataApi} from "@/api";


const heatmap = ref()
const option = ref<EChartsOption>()
const myChart = ref<EChartsType>()
const heatmapData = ref({
  data:[]
})
const init = async () => {
  const {data:res} = await useGetHeatmapDataApi()
  heatmapData.value = res
  myChart.value = markRaw(echarts.init(heatmap.value));
  draw();
}
const draw = () => {
  option.value = {
    title:{
      text:'2023年11月电影总票房top1的热度趋势',
      left:'center',
      textStyle:{
        color:'#000000'
      }
    },
    tooltip: {},
    calendar: {
      top: 'middle',
      left: 'center',
      orient: 'vertical',
      cellSize: 40,
      yearLabel: {
        margin: 50,
        fontSize: 30
      },
      dayLabel: {
        firstDay: 1,
        nameMap: 'ZH'
      },
      monthLabel: {
        nameMap: 'ZH',
        margin: 15,
        fontSize: 20,
        color: '#999'
      },
      range: ['2023-11']
    },
    visualMap: {
      min: 0,
      max: 6000,
      type: 'piecewise',
      left: 'center',
      bottom: 20,
      orient: 'horizontal'
    },
    series: [
      {
        type: 'heatmap',
        coordinateSystem: 'calendar',
        data: heatmapData.value.data
      }
    ]
  }
  myChart.value.setOption(option.value, {notMerge: true});
}
onMounted(() => {
  init()
})
</script>

<template>
  <div ref="heatmap" class="heatmap">
  </div>
</template>

<style scoped>
.heatmap{
  width: 100%;
  height: 100%;
}
</style>